/**
 * Created by kogting on 14-7-3.
 */
function districtsPopup(options){
    var title = options.title;
    var width = options.width;
    var height = options.height;
    var Html = '';
    Html += '<div class="search"><span class="fc-gray">请搜索地理位置：</span><div class="search-input" style=""><input id="districtsearch-info" type="text" value=""><span id="districtdeleInput" class="close-tag mt1"></span></div><input id="districtsearchBtn" type="button" class="btn-pop search-btn" value="搜索"></div>';
    Html +='<div class="search-result"><div class="add-all"><a id="districtaddResults" href="javascript:;">全部添加<span class="adddistrict add-icon"></span></a></div></div>';
    Html += '<div class="district-set"><div class="list-con"><div class="name">请选择地理位置<a href="javascript:;" style="color:#36aeea;text-decoration:none;" id="districtselect_all">全选</a></div><div class="con"><div id="j-districtList"></div></div></div><div class="districtselected-con"><div class="name">已选择的地理位置<a href="javascript:;" style="color:#36aeea;text-decoration:none;" id="district_unselect_all">清空</a></div><div class="con"></div></div><div class="district-bottom row-fluid"><a href="javascript:;" id="districtsconfirm" style="margin-left:618px;margin-top:18px;display: block; text-align: center; font-size:14px;line-height:30px;background-color: #68ba31;width:115px; height:30px;color:white;border-radius:5px 5px 5px 5px;cursor: pointer;text-decoration:none;" class="btn-pop btn-success span2">确定</a></div></div>';
    var template = '<div id="districts_mask" class="mask"></div>'+
        '<div id="district_popup" class="popup" style="z-index:110; ">'+
        '<div class="title">'+
        '<strong>'+title+'</strong>'+
        '<span id="close" class="close-tag"></span>'+
        '<span class="restore-tag"></span>'+
        '<span class="max-tag"></span>'+
        '</div>'+
        '<div class="popup-content">'+
        Html+
        '</div>'+
        '</div>';
    $("#district_layout").append(template);

    var popup = $("#district_popup");
    popup.css({
        'width':width,
        'left':($(window).width() - parseInt(width))/2 + 'px'
    });
    popup.css({
        height:height,
        top:($(window).height() - parseInt(height))/900 + 'px'
    });

    this.opt = $.extend({
        masker: true,
        width:'60%',
        height:'60%',
        title:'',
        zIndex:110,
        forceRemove:false
    },options);

    this.mask = $("#districts_mask");
    this.max = popup.find('.max-tag');
    this.restore = popup.find('.restore-tag');
    this.content = popup.find('.popup-content');
    this.close = popup.find('#close');
    this.close.click(function(){
        this.hide();
        this.mask.hide();
    }.bind(this));
    this.hide = function(){
        if (this.opt.forceRemove) {
            popup.empty().remove();
            this.mask.empty().remove();
        }else{
            popup.hide();
            this.mask.hide();
        }
        $(document.body).css({overflow:'auto'});
    };
    this.show = function(){
        popup.show();
        this.mask.show();
    };
    this.remove = function(){
        popup.remove();
        this.mask.remove();
    }
}